package com.xh3140.xwidget.table;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;

public class NestedTableView extends LinearLayoutCompat {
  public NestedTableView(@NonNull Context context) {
    this(context, null);
  }

  public NestedTableView(@NonNull Context context, @Nullable AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public NestedTableView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setOrientation(VERTICAL);
    setShowDividers(SHOW_DIVIDER_MIDDLE);
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(Color.BLACK);
    drawable.setSize(1, 1);
    setDividerDrawable(drawable);
  }

  public void addNestedTableRow(@NonNull NestedTableRow tableRow) {
    addView(tableRow, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
  }

  public void addViewAsRow(@NonNull View rowView) {
    addView(rowView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
  }
}
